
import javax.microedition.lcdui.Graphics;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author luciana
 */
public class Button extends Drawable {

    public String text;
    public int w;
    public int h;
    private final ButtonListener listener;
    public boolean drawBorder;

    public Button(String text, ButtonListener listener, ButtonConfig config) {
        this.text = text;
        this.listener = listener;
        this.w = config.width;
        this.h = config.height;
        this.drawBorder = true;
    }

    public void draw(Graphics g) {
        g.setColor(0);
        if (drawBorder) {
            g.drawRect((int) getX(), (int) getY(), w, h);
        }
        g.setColor(0xffffff);
        g.drawString(text, (int) getX() + 1, (int) getY() + 1, 0);
    }

    public boolean clicked(int x, int y) {
        return x >= this.getX() && y >= this.getY() && x <= this.getX() + w && y <= this.getY() + h;
    }

    public void click() {
        ClickEvent evt = new ClickEvent();
        evt.text = this.text;
        listener.buttonClicked(evt);
    }
}
